"""
定义 接口对象层 类、方法
"""
import requests


class IhrmEmpApi(object):
    # 添加员工
    @classmethod
    def add_emp(cls, req_header, req_body):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers=req_header, json=req_body)
        return resp

    # 查询员工 - 注意参数顺序
    @classmethod
    def query_emp(cls, emp_id, req_header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id, headers=req_header)
        return resp

    # 修改员工
    @classmethod
    def modify_emp(cls, emp_id, req_header, req_body):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header, json=req_body)
        return resp

    # 删除员工
    @classmethod
    def delete_emp(cls, emp_id, req_header):
        return requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id, headers=req_header)


if __name__ == '__main__':
    # 准备请求头
    req_header = {"Authorization": "c58874b4-2943-4cdc-bf41-b6a04f6479d1"}
    req_body = {
        "username": "user87655430",
        "mobile": "17382985401",
        "workNumber": "9527890aa"
    }
    # 添加员工  测试
    # resp = IhrmEmpApi.add_emp(req_header, req_body)
    # print("添加员工：", resp.json())

    # 准备员工 id
    emp_id = "1516338176271171584"

    # 查询员工  测试
    resp = IhrmEmpApi.query_emp(emp_id, req_header)
    print("查询员工：", resp.json())

    # 修改员工  测试
    mod_req_body = {"username": "至宗宝99"}
    resp = IhrmEmpApi.modify_emp(emp_id, req_header, mod_req_body)
    print("修改员工：", resp.json())

    # 删除员工  测试
    resp = IhrmEmpApi.delete_emp(emp_id, req_header)
    print("删除员工：", resp.json())
